
import 'package:flutter/material.dart';
import 'package:flutter_project/common/route_page/route_name.dart';

import '../splash/splash_page.dart';

/// Generate routes, we can pass arguments from here
Route<dynamic> generateRoutes(RouteSettings? settings) {
  final name = settings?.name ?? '/';
  final uri = Uri.parse(name);
  final params = uri.queryParameters;
  debugPrint(params.toString());
  final rootName = name.contains('?') ? name.substring(0, name.indexOf('?')) : name;
  switch (rootName) {
    case RouteNames.initialPage:
    case RouteNames.splashPage:
      return _generatePageRoute(const SplashPage(), settings);
    default:
      return _generatePageRoute(const SplashPage(), settings);
  }
}

/// Generate material page route
_generatePageRoute(final Widget widget, RouteSettings? settings) => MaterialPageRoute(
  builder: (_) => widget,
  settings: settings,
);